#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Time    : 2024-8-12 9:52
# @Author  : jiaoxianzhong
# @File    : string_helper.py
# @Software: PyCharm
import sys

from pymysql.converters import escape_string


# 处理字符串中的引号
def handle_quotation_marks(value):
    if "'" in value:
        value = value.replace("'", "\\'")
    if '"' in value:
        if value[0] == '"' and value[-1] == '"':
            value = value[1:-1]
        else:
            value = value.replace('"', '\\"')
    return value


if __name__ == '__main__':
    my_title = "我是'单引号'," + '"我是双引号"'
    print(f"\n{handle_quotation_marks(my_title)}")
    print(f"\n{escape_string(my_title)}")
